/**
 * 控件 - 提示文字
 */
import { messages } from "share/common";
import React from 'react'
import { connect } from 'react-redux'
import { Checkbox } from 'antd'

import { LanguageInput } from 'components/index'

class FieldPrompt extends React.Component{
  constructor(props) {
    super(props);
    this.state = {

    }
  }

  render() {
    const { widget, onChange, onSettingChange } = this.props;
    let tenantMode = this.props.currentMenuPermission.currentMenuPermission.authPolicyAll;
    return (
      <div className="field-prompt">
        {messages('expense-6.key15')/*类型*/}: {widget.name}
        <div className="widget-setting-title">{widget.name}</div>
        <LanguageInput
          isEdit
          textArea
          name={widget.placeholder}
          i18nName={JSON.parse(JSON.stringify(widget.i18n.placeholder || []))}
          placeholder={messages('common.please.input')/*请输入*/}
          nameChange={onChange}
          disabled={!tenantMode}
          inpRule={[{
            length: 200,
            language: "zh_cn"
          }, {
            length: 600,
            language: "en"
          }]}
        />
        <div className="widget-setting-title">
          <Checkbox
            checked={(widget.config || {}).showOnEdit}
            disabled={!tenantMode}
            onChange={e => onSettingChange(e, 'showOnEdit')}
          >
            {messages('expense-6.key104')/*仅在编辑时展示*/}
          </Checkbox>
        </div>
      </div>
    )
  }
}

FieldPrompt.contextTypes = {
  widget: React.PropTypes.object,
  onChange: React.PropTypes.func,
  onSettingChange: React.PropTypes.func,
};

function mapStateToProps(state) {
  return {
    currentMenuPermission: state.main.currentMenuPermission,
  }
}

export default connect(mapStateToProps)(FieldPrompt)
